#include "./../inc/popup.h"

MenuPopup *MenuPopup::m_instance = NULL;

MenuPopup *MenuPopup::instance(GameManager *gameManager, Lcd *lcd)
{
    // 如果没有实例则创建实例
    if (m_instance == NULL)
    {
        m_instance = new MenuPopup(gameManager, lcd);
    }
    return m_instance;
}

void MenuPopup::delInstance()
{
    // 释放实例空间
    delete m_instance;
    m_instance = NULL;
}

bool MenuPopup::handleTouch(const Point &touch_point)
{
    if (touch_point.x() >= (100 + 100) && touch_point.x() <= (400 + 100) && touch_point.y() >= 105 && touch_point.y() <= 155)
    {
        continueGame();
        return true;
    }
    else if (touch_point.x() >= (100 + 100) && touch_point.x() <= (400 + 100) && touch_point.y() >= 210 && touch_point.y() <= 260)
    {
        restartGame();
        return true;
    }
    else if (touch_point.x() >= (100 + 100) && touch_point.x() <= (400 + 100) && touch_point.y() >= 340 && touch_point.y() <= 370)
    {
        reBackMainPage();
        return true;
    }
    else
    {
        return false;
    }
}

void MenuPopup::continueGame()
{
    gameManager->reloadGame();
}

void MenuPopup::restartGame()
{
    gameManager->showLevelPopup();
}

void MenuPopup::reBackMainPage()
{
    gameManager->showMainPage();
}

// 显示页面实现
void MenuPopup::show()
{
    bg.show(lcd->addr(), 100, 40);
}

// 隐藏页面实现
void MenuPopup::hide() {}

//--------------------------------------------------------------------------------------//

LevelPopup *LevelPopup::m_instance = NULL;

LevelPopup *LevelPopup::instance(GameManager *gameManager, Lcd *lcd)
{
    // 如果没有实例则创建实例
    if (m_instance == NULL)
    {
        m_instance = new LevelPopup(gameManager, lcd);
    }
    return m_instance;
}

void LevelPopup::delInstance()
{
    // 释放实例空间
    delete m_instance;
    m_instance = NULL;
}

bool LevelPopup::handleTouch(const Point &touch_point)
{
    if (touch_point.x() >= (190 + 100) && touch_point.x() <= (400 + 100) && touch_point.y() >= 90 && touch_point.y() <= 152)
    {
        startGame(0);
        return true;
    }
    else if (touch_point.x() >= (190 + 100) && touch_point.x() <= (400 + 100) && touch_point.y() >= 210 && touch_point.y() <= 260)
    {
        startGame(1);
        return true;
    }
    else if (touch_point.x() >= (190 + 100) && touch_point.x() <= (400 + 100) && touch_point.y() >= 320 && touch_point.y() <= 370)
    {
        startGame(2);
        return true;
    }
    else if (touch_point.x() >= (10 + 100) && touch_point.x() <= (60 + 100) && touch_point.y() >= 50 && touch_point.y() <= 100)
    {
        backPrevPage();
        return true;
    }
    else
    {
        return false;
    }
}

void LevelPopup::startGame(int level)
{
    gameManager->gameInit(level);
}

void LevelPopup::backPrevPage()
{
    gameManager->backPage();
}

// 显示页面实现
void LevelPopup::show()
{
    bg.show(lcd->addr(), 100, 40);
    back.showIcon(lcd->addr(), 110, 50);
}

// 隐藏页面实现
void LevelPopup::hide() {}